#pragma once
#include <fastdds/dds/topic/Topic.hpp>
#include <fastdds/dds/subscriber/DataReaderListener.hpp>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/subscriber/Subscriber.hpp>
#include "LogMsg.h"
namespace DDS_PARAMETER {
	enum ReturnCode;
	struct DDS_Attribute;
};
class CSubscriber{
public:
	class SubscriberListener : public eprosima::fastdds::dds::DataReaderListener
	{
	public:
		SubscriberListener();
		~SubscriberListener() override;
		void on_data_available(
			eprosima::fastdds::dds::DataReader* reader) override;

		void on_subscription_matched(
			eprosima::fastdds::dds::DataReader* reader,
			const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) override;
		void on_sample_lost(
			eprosima::fastdds::dds::DataReader* reader,
			const eprosima::fastdds::dds::SampleLostStatus& status) override;
		void set_callback(uint32_t ref);
		bool has_matched();
		std::string get_last_msg();
		uint64_t get_timestamp();
	private:
		int matched_;
		uint32_t call_back_ref_;
		std::string last_msg_;
		uint64_t timestamp_;
	};
public:
	CSubscriber(eprosima::fastdds::dds::DomainParticipant* participant);
	~CSubscriber();
	DDS_PARAMETER::ReturnCode create_subscriber(eprosima::fastdds::dds::Topic* topic, std::string profile, uint32_t call_back_ref);
	bool has_matched();
	DDS_PARAMETER::ReturnCode create_subscriber(eprosima::fastdds::dds::Topic* topic, const DDS_PARAMETER::DDS_Attribute& dds_attr);
	DDS_PARAMETER::ReturnCode create_subscriber(eprosima::fastdds::dds::Topic* topic, uint32_t call_back_refs);
private:
	SubscriberListener m_listener_;
	eprosima::fastdds::dds::Subscriber* m_subscriber_;
	eprosima::fastdds::dds::DomainParticipant* m_participant_;
	
};